package com.glorysoft.hlgdpda.ui.main.view

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.glorysoft.hlgdpda.BR
import com.glorysoft.hlgdpda.R
import com.glorysoft.hlgdpda.base.BaseActivity
import com.glorysoft.hlgdpda.databinding.ActivityMainBinding
import com.glorysoft.hlgdpda.ui.main.viewmodel.MainViewModel
import com.glorysoft.hlgdpda.ui.setting.view.SettingActivity
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_TabIndexGridEntity
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_TitleView
import kotlinx.android.synthetic.main.activity_main.*

/**
 * FileName: MainActivity
 * Author: XJH
 * Date: 2021/5/13 17:03
 * Description:
 * History:
 */
class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
    override fun layoutId(): Int {
        return R.layout.activity_main
    }

    override fun initVariableId(): Int {
        return BR.mainViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        viewModel.initAssets(this)
        viewModel.defUI.callObserve.observe(this){
            when(it.type){
                viewModel.START_ACTIVITY -> {
                    val intent = Intent()

                    try {
                        val entity = it.item as FreeUI_TabIndexGridEntity
                        val clazz = Class.forName(entity.skipClass)
                        intent.putExtra("showPlugin", entity.showPlugin)
                        intent.setClass(this, clazz)
                    } catch (var4: Exception) {
                        var4.printStackTrace()
                    }
                    startActivity(intent)
                }
                viewModel.MFGLAYOUT -> llMFGLayout.visibility = View.GONE
                viewModel.CHECKLAYOUT -> llCheckLayout.visibility = View.GONE
            }
        }
    }

    override fun initData() {
        ivSetting.setOnClickListener{
            startActivity(SettingActivity::class.java)
        }
    }
}